package com.dhy.dead;

import com.dhy.util.RabbitmqUtil;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import static com.dhy.constants.RabbitmqConstants.*;

/**
 * @author 大忽悠
 * @create 2022/5/21 21:10
 */
@Slf4j
public class DeadConsumer implements Runnable{
    @Override
    public void run() {
        try {
            RabbitmqUtil rabbitmqUtil = new RabbitmqUtil("application.yml");
            Channel channel = rabbitmqUtil.createChannel();
            //直接进行消费的消息--所有声明操作已经在生产者部分完成
            channel.basicConsume(DEAD_QUEUE,false,(consumerTag, message) -> {
                log.info("消息为: {}",new String(message.getBody()));
                log.info("头信息打印: {}",message.getProperties().getHeaders());
                channel.basicAck(message.getEnvelope().getDeliveryTag(),true);
            },consumerTag -> {});
        } catch (IOException | TimeoutException e  ) {
            log.error("出现异常: ",e);
        }
    }
}
